import pygame
import random
from player import Player
from block import Block
from constants import music_list
from info import Info
from constants import SCREEN_WIDTH, SCREEN_HEIGHT


class LoadPicture:

    def __init__(self, img_path, size):
        self.image = pygame.transform.smoothscale(pygame.image.load(img_path), size)


class LoadSound:
    pygame.init()

    def __init__(self, sound_path):
        self.sound = pygame.mixer.Sound(sound_path)

    def play_sound(self):
        self.sound.play()


# bgm的随机播放
class Music:
    def __init__(self, music_file):
        self.music_file = music_file
        current_music = random.choice(self.music_file)
        pygame.mixer.music.load(current_music)
        pygame.mixer.music.play()

    def play(self):
        if not pygame.mixer.music.get_busy():
            if self.music_file:
                current_music = random.choice(self.music_file)
                pygame.mixer.music.load(current_music)
                pygame.mixer.music.play()


# 创建玩家对象
player = Player()
players = pygame.sprite.Group()
players.add(player)

# 创建敌人
enemies = pygame.sprite.Group()
enemies.add(Block())

# bgm的加载
bgm = Music(music_list)

# 提示信息的加载
dead_info = Info('Game over!', None, 72,
                 (255, 255, 255), (255, 0, 0),
                 (SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2))

